struct ListNode* MiddleNode(struct ListNode* head)
{
    struct ListNode* fast = head;
    struct ListNode* slow = head;
    while (fast && fast->next)
    {
        fast = fast->next->next;
        slow = slow->next;
    }
    return slow;
}
struct ListNode* ReverseList(struct ListNode* head)
{
    struct ListNode* n1 = NULL;
    struct ListNode* n2 = head;
    struct ListNode* n3 = head;
    while (n2)
    {
        n3 = n3->next;
        n2->next = n1;
        n1 = n2;
        n2 = n3;
    }
    return n1;
}
bool isPalindrome(struct ListNode* head) {
    struct ListNode* mid = MiddleNode(head);
    struct ListNode* rmid = ReverseList(mid);
    while (rmid && head)
    {
        if (head->val != rmid->val)
        {
            return false;
        }
        head = head->next;
        rmid = rmid->next;
    }
    return true;
}